home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / io / FileSystem.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  6.3 KB  |  206 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)FileSystem.java    1.5 98/08/26
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17.  
  18. /**
  19.  * Package-private abstract class for the local filesystem abstraction.
  20.  */
  21.  
  22. abstract class FileSystem {
  23.  
  24.     /**
  25.      * Return the FileSystem object representing this platform's local
  26.      * filesystem.
  27.      */
  28.     public static native FileSystem getFileSystem();
  29.  
  30.  
  31.     /* -- Normalization and construction -- */
  32.  
  33.     /**
  34.      * Return the local filesystem's name-separator character.
  35.      */
  36.     public abstract char getSeparator();
  37.  
  38.     /**
  39.      * Return the local filesystem's path-separator character.
  40.      */
  41.     public abstract char getPathSeparator();
  42.  
  43.     /**
  44.      * Convert the given pathname string to normal form.  If the string is
  45.      * already in normal form then it is simply returned.
  46.      */
  47.     public abstract String normalize(String path);
  48.  
  49.     /**
  50.      * Compute the length of this pathname string's prefix.  The pathname
  51.      * string must be in normal form.
  52.      */
  53.     public abstract int prefixLength(String path);
  54.  
  55.     /**
  56.      * Resolve the child pathname string against the parent.
  57.      * Both strings must be in normal form, and the result
  58.      * will be in normal form.
  59.      */
  60.     public abstract String resolve(String parent, String child);
  61.  
  62.     /**
  63.      * Return the parent pathname string to be used when the parent-directory
  64.      * argument in one of the two-argument File constructors is the empty
  65.      * pathname.
  66.      */
  67.     public abstract String getDefaultParent();
  68.  
  69.  
  70.     /* -- Path operations -- */
  71.  
  72.     /**
  73.      * Tell whether or not the given abstract pathname is absolute.
  74.      */
  75.     public abstract boolean isAbsolute(File f);
  76.  
  77.     /**
  78.      * Resolve the given abstract pathname into absolute form.  Invoked by the
  79.      * getAbsolutePath and getCanonicalPath methods in the File class.
  80.      */
  81.     public abstract String resolve(File f);
  82.  
  83.     public abstract String canonicalize(String path) throws IOException;
  84.  
  85.  
  86.     /* -- Attribute accessors -- */
  87.  
  88.     /* Constants for simple boolean attributes */
  89.     public static final int BA_EXISTS    = 0x01;
  90.     public static final int BA_REGULAR   = 0x02;
  91.     public static final int BA_DIRECTORY = 0x04;
  92.     public static final int BA_HIDDEN    = 0x08;
  93.  
  94.     /**
  95.      * Return the simple boolean attributes for the file or directory denoted
  96.      * by the given abstract pathname, or zero if it does not exist or some
  97.      * other I/O error occurs.
  98.      */
  99.     public abstract int getBooleanAttributes(File f);
  100.  
  101.     /**
  102.      * Check whether the file or directory denoted by the given abstract
  103.      * pathname may be accessed by this process.  If the second argument is
  104.      * <code>false</code>, then a check for read access is made; if the second
  105.      * argument is <code>true</code>, then a check for write (not read-write)
  106.      * access is made.  Return false if access is denied or an I/O error
  107.      * occurs.
  108.      */
  109.     public abstract boolean checkAccess(File f, boolean write);
  110.  
  111.     /**
  112.      * Return the time at which the file or directory denoted by the given
  113.      * abstract pathname was last modified, or zero if it does not exist or
  114.      * some other I/O error occurs.
  115.      */
  116.     public abstract long getLastModifiedTime(File f);
  117.  
  118.     /**
  119.      * Return the length in bytes of the file denoted by the given abstract
  120.      * pathname, or zero if it does not exist, is a directory, or some other
  121.      * I/O error occurs.
  122.      */
  123.     public abstract long getLength(File f);
  124.  
  125.  
  126.     /* -- File operations -- */
  127.  
  128.     /**
  129.      * Create a new empty file with the given pathname.  Return
  130.      * <code>true</code> if the file was created and <code>false</code> if a
  131.      * file or directory with the given pathname already exists.  Throw an
  132.      * IOException if an I/O error occurs.
  133.      */
  134.     public abstract boolean createFileExclusively(String pathname)
  135.     throws IOException;
  136.  
  137.     /**
  138.      * Delete the file or directory denoted by the given abstract pathname,
  139.      * returning <code>true</code> if and only if the operation succeeds.
  140.      */
  141.     public abstract boolean delete(File f);
  142.  
  143.     /**
  144.      * Arrange for the file or directory denoted by the given abstract
  145.      * pathname to be deleted when the VM exits, returning <code>true</code> if
  146.      * and only if the operation succeeds.
  147.      */
  148.     public abstract boolean deleteOnExit(File f);
  149.  
  150.     /**
  151.      * List the elements of the directory denoted by the given abstract
  152.      * pathname.  Return an array of strings naming the elements of the
  153.      * directory if successful; otherwise, return <code>null</code>.
  154.      */
  155.     public abstract String[] list(File f);
  156.  
  157.     /**
  158.      * Create a new directory denoted by the given abstract pathname,
  159.      * returning <code>true</code> if and only if the operation succeeds.
  160.      */
  161.     public abstract boolean createDirectory(File f);
  162.  
  163.     /**
  164.      * Rename the file or directory denoted by the first abstract pathname to
  165.      * the second abstract pathname, returning <code>true</code> if and only if
  166.      * the operation succeeds.
  167.      */
  168.     public abstract boolean rename(File f1, File f2);
  169.  
  170.     /**
  171.      * Set the last-modified time of the file or directory denoted by the
  172.      * given abstract pathname, returning <code>true</code> if and only if the
  173.      * operation succeeds.
  174.      */
  175.     public abstract boolean setLastModifiedTime(File f, long time);
  176.  
  177.     /**
  178.      * Mark the file or directory denoted by the given abstract pathname as
  179.      * read-only, returning <code>true</code> if and only if the operation
  180.      * succeeds.
  181.      */
  182.     public abstract boolean setReadOnly(File f);
  183.  
  184.  
  185.     /* -- Filesystem interface -- */
  186.  
  187.     /**
  188.      * List the available filesystem roots.
  189.      */
  190.     public abstract File[] listRoots();
  191.  
  192.  
  193.     /* -- Basic infrastructure -- */
  194.  
  195.     /**
  196.      * Compare two abstract pathnames lexicographically.
  197.      */
  198.     public abstract int compare(File f1, File f2);
  199.  
  200.     /**
  201.      * Compute the hash code of an abstract pathname.
  202.      */
  203.     public abstract int hashCode(File f);
  204.  
  205. }
  206.